var urlse = "http://192.168.10.246:9000/",
server_url = "http://192.168.10.246:8888"
exports.base = {
	install: function(Vue, options) {
		/* 默认get  */
		Vue.prototype.ajax = function(url, canshu, ty,isload) {
			return new Promise((resolve, reject) => {
				uni.request({
					url:  server_url + url,
					method: ty||"GET",
					data: canshu,
					success: (res) => {
						resolve(res.data)
					},
					complete: (res) => {
						
					}
				});
			})
		}
		
		
		/* 默认get  */
		Vue.prototype.ajaxLogin = function(url, canshu, ty,isload) {
			if (isload){
				uni.showLoading()
			}
			return new Promise((resolve, reject) => {
				uni.request({
					url:  urlse + url,
					method: ty||"GET",
					header:{
						'Authorization':'Basic XXXXXX'
					},
					data: canshu,
					success: (res) => {
						if (res.data.code !=200){
							uni.showToast({
								icon:"none",
								title:res.data.msg
							})
							return
						}
						resolve(res.data)
					},
					complete: (res) => {
						uni.hideLoading()
					}
				});
			})
		}

		Vue.prototype.hf = function(urls) {
			console.log(urls)
			uni.navigateTo({
				url: urls
			})
		}

		Vue.prototype.time_c = function(t) {
			let time = new Date()
			time.setTime(t * 1000)
			let Year = time.getFullYear(),
				Month = time.getMonth() + 1,
				Data = time.getDate() < 10 ? 0 + '' + time.getDate() : time.getDate()
			Month < 10 ? Month = 0 + '' + Month : Month = Month
			return Year + "-" + Month + "-" + Data
		}

		Vue.prototype.time_d = function(t) {
			let time = new Date()
			time.setTime(t * 1000)
			let Year = time.getFullYear(),
				Month = time.getMonth() + 1,
				Data = time.getDate() < 10 ? 0 + '' + time.getDate() : time.getDate(),
				hour = time.getHours() < 10 ? 0 + '' + time.getHours() : time.getHours(),
				Minutes = time.getMinutes() < 10 ? 0 + '' + time.getMinutes() : time.getMinutes(),
				Seconds = time.getSeconds() < 10 ? 0 + '' + time.getSeconds() : time.getSeconds()
			Month < 10 ? Month = 0 + '' + Month : ''
			return Year + "年" + Month + "月" + Data + "日 " + hour + ":" + Minutes + ":" + Seconds
		}



		Vue.prototype.yanza = {
			mail: function(a) {
				var b = !1;
				return /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(a) && (b = !0), b
			},
			phone: function(a) {
				var b = !1;
				return a.match(/^13[0-9]{9}|15[0-9]{9}|17[0-9]{9}|18[0-9]{9}$/) && 11 == a.length && (b = !0), b
			},
			car_t: function(a) {
				var b = !1;
				return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/
					.test(a) && (b = !0), b
			}
		};
		// 获取mac地址
		Vue.prototype.getMac = function(){
			var net = plus.android.importClass("java.net.NetworkInterface")
			var wl0 = net.getByName('wlan0')
			var macByte = wl0.getHardwareAddress()
			var str = []
			//下面这段代码来自网络  
			for (var i = 0; i < macByte.length; i++) {
				var tmp = "";
				var num = macByte[i];
				if (num < 0) {
					tmp = (255 + num + 1).toString(16);
				} else {
					tmp = num.toString(16);
				}
				if (tmp.length == 1) {
					tmp = "0" + tmp;
				}
				// str += tmp;
				str.push(tmp)
			}
			return str.join(":")
		}
	}
}